﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameWork.Source.Object_Classes;
using Microsoft.Xna.Framework;

namespace Boomer.Source.QuadTree
{
    class CQuadTreeNode
    {
        #region Variables

        public ulong nodeLevel { get; private set; }
        public long upperLeftX { get; private set; }
        public long upperLeftY { get; private set; }
        public long width { get; private set; }
        public long height { get; private set; }

        List<CObject> listObject;

        public CQuadTreeNode[] pSubNode;
        public CQuadTreeNode pParentNode { get; private set; }

        #endregion

        #region Constructor

        public CQuadTreeNode(CQuadTreeNode pParentNode, long upperLeftX, long upperLeftY, long width, long height)
        {
            this.upperLeftX = upperLeftX;
            this.upperLeftY = upperLeftY;
            this.width = width;
            this.height = height;

            if (pParentNode == null)
            {
                this.nodeLevel = 1;
                this.pParentNode = null;
            }
            else
            {
                this.nodeLevel = pParentNode.nodeLevel + 1;
                this.pParentNode = pParentNode;
            }
            listObject = new List<CObject>();
            pSubNode = null;
        }

        #endregion


        #region Methods

        public void addObject(CObject pObject)
        {
            listObject.Add(pObject);
        }

        public bool removeObject(CObject pOjbect)
        {
            int size = listObject.Count;

            for (int i = 0; i < size; ++i)
            {
                if (listObject[i] == pOjbect)
                {
                    listObject.RemoveAt(i);
                    return true;
                }
            }

            return false;
        }

        public bool getObject(ref List<CObject> pListObject)
        {
            int size = listObject.Count;
            if (size <= 0)
                return false;

            for (int i = 0; i < size; ++i)
            {
                pListObject.Add(listObject[i]);
            }

            return true;
        }

        public Rectangle getSize()
        {
            Rectangle recBound = new Rectangle((int)upperLeftX, (int)upperLeftY, (int)width, (int)height);

            return recBound;
        }


        public void release()
        {
            this.listObject.Clear();
        }

        

        #endregion
    }
}
